﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Edu;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.Possy
{
    public partial class PossyList : UseMorePageMasterPage
    {
        /// <summary>
        /// 页数
        /// </summary>
        private string PageIndex
        {
            get
            {
                return this.Request["PageIndex"] ?? "";
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private string DataCount
        {
            get
            {
                return this.Request["DataCount"] ?? "";
            }
        }
        /// <summary>
        /// 每页条数
        /// </summary>
        private string PageSize
        {
            get
            {
                return this.Request["PageSize"] ?? "";
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private string QueryText
        {
            get
            {
                return this.Request["QueryText"] ?? "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }

            if (!string.IsNullOrEmpty(this.PageIndex))
            {
                this.WriteList();
            }
            else if(!string.IsNullOrEmpty(this.DataCount))
            {
                WriteDataCount();

            }
        }
        public void LoadData()
        {

        }

        public Dictionary<string, string> dicVisitDaysName
        {
            get
            {
                var dic = new Dictionary<string, string>();
                dic.Add("1","星期一");
                dic.Add("2", "星期二");
                dic.Add("3", "星期三");
                dic.Add("4", "星期四");
                dic.Add("5", "星期五");
                dic.Add("6", "星期六");
                dic.Add("7", "星期日");
                return dic;
            }
        }

        private void WriteList()
        {
            StringBuilder sbHtml = new StringBuilder();
            
            DataTable dt = PartyPossyInfo.GetGridData(Convert.ToInt32(this.PageIndex), Convert.ToInt32(PageSize), "1", "", this.QueryText).Tables[0];
            dt.Columns.Add("VisitDaysName", typeof (string));
            foreach (DataRow dr in dt.Rows)
            {
                var temp = Convert.ToString(dr["VisitDays"]);
                foreach (var key in Convert.ToString(dr["VisitDays"]).Split(','))
                {
                    temp = temp.Replace(key,dicVisitDaysName[key]);
                }
                dr["VisitDaysName"] = temp;
            }
            var json = JsonConvert.SerializeObject(dt);
            Response.Clear();
            Response.Write(json);
            Response.End();
        }
        private void WriteDataCount()
        {
            Response.Clear();
            Response.Write(PartyPossyInfo.GetGridData(0, 1, "1", "", this.QueryText).Tables[1].Rows[0][0].ToString());
            Response.End();
        }
        
    }
}